<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="cn.nwpu.eckel.model.*" %>
<%@ page import="cn.nwpu.eckel.Dao.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%
String account=(String)session.getAttribute("account");
System.out.println(account);
User user=UserDao.getUserByAccount(account);
String name=user.getName();
int authority=user.getAuthority();
String status="";
if(authority==0){
	status="计划员";
}else if(authority==1){
	status="管理员";
}else if(authority==2){
	status="超级管理员";
}
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link rel="stylesheet" type="text/css" href="style/generalstyle.css"/>
	<link rel="stylesheet" type="text/css" href="style/indexstyle.css"/>

  </head>
  
  <body>
  	 <div class="header">
    	<div class="logobox"><img src="images/logo.png" /></div><span>滚动式主生产计划管理系统</span>
    </div>
    <div class="mainbody">
    	<div class="leftbar">
    		<div class="lefttop">
    			<img src="images/portrait.png" class="portrait"/>
    			<div class="identity">
    				<span><%=name%></span>
    				<p><%=status%></p>
    			</div>
    			<a href="#"><img src="images/profile.png" class="profile" /></a>
    		</div>
    		<div class="leftbottom">
    			<div class="item">
    				<a href="new.jsp?type=mps"><span>MPS</span></a>
    				<a href="new.jsp?type=forecast"><span>预测</span></a>
    				<a href="new.jsp?type=order"><span>订单</span></a>
    				<a href="new.jsp?type=schedulereceipt"><span>接收</span></a>
    				<span> + </span>
    			</div>
    			<div class="searchbox">
    				<form class="searchform" name="searchform" method="post" action="">
    					<input class="searchInput" name="mpsNo" type="text" placeholder="输入MPS的编号">
    					<input class="searchButton" type="image" src="images/searcher.png" />
    				</form>
    				<div class="searchresult">
    				<%
    				String result;
					String str=request.getParameter("mpsNo");
					if(str!=null){
						int mpsNo=Integer.parseInt(str);
						MPS mps=MPSDao.getMPSById(mpsNo);
    					if(mps.id!=0){
    						result=mps.id+"---"+mps.pNo+"---"+mps.pName+"---"+mps.planner+"---"+mps.buildTime;
    				%>
    						<a href="index.jsp?mpsId=<%=mps.id%>"><%=result %></a>
    				<%
    					}
					}
						
    				%>
    				</div>
    			</div>
    			<div class="mpslist">
    			<%
    			String mlist;
    			List<MPS> mpses=MPSDao.getAllMPS();
    			if(!mpses.isEmpty()){
    				for(MPS m:mpses){
    					mlist=m.id+"--"+m.pNo+"--"+m.pName+"--"+m.planner+"--"+m.ph+"--"+m.lt;
    			%>
    			<a href="index.jsp?mpsId=<%=m.id%>"><%=mlist %></a>
    			<%
    				}
    			}
    			
    			%>
    		</div>
    		</div>
    	</div>
    	<div class="rightbody">
    		
    		<%
    		int id;
    		String idstr=request.getParameter("mpsId");
    		if(idstr!=null){
    			id=Integer.parseInt(idstr); 			
    		%>
    		
    		
    		<div class="navbar">
    		     <img src="images/mps.png"/>
    			 <p class="mpsNo">MPS:<%=id %>/</p>
    			 <div class="nav">
	    			 <a href="index.jsp?mpsId=<%=id%>&source=forecast"><span>预测</span></a>
	    			 <a href="index.jsp?mpsId=<%=id%>&source=order"><span>订单</span></a>
	    			 <a href="index.jsp?mpsId=<%=id%>&source=schedulereceipt"><span>预计接收量</span></a>
	    		 </div>
	    	</div>
	    	<div class="source">
	    		<%
	    		String source="order";
	    		List<Source> sourcelist=new ArrayList<Source>();
	    		String theSource=request.getParameter("source");
				if(theSource!=null){
					source=theSource;	
	    		}
	    		if(source.equals("order")){
	    		   	List<Order> sources;
	    			sources=OrderDao.getOrdersByMpsNo(id);
	    			for(Order odr:sources){
	    				sourcelist.add(odr);
	    			}
	    		}else if(source.equals("forecast")){
	    			List<Forecast> sources;
	    			sources=ForecastDao.getForecastsByMpsNo(id);
	    			for(Forecast fc:sources){
	    				sourcelist.add(fc);
	    			}
	    		}else{
	    			List<ScheduleReceipt> sources;
	    			sources=ScheduleReceiptDao.getScheduleReceiptsByMpsNo(id);
	    			for(ScheduleReceipt sr:sources){
	    				sourcelist.add(sr);
	    			}
	    		}
	    		%>
		    	<p><%=source %></p>
			    <div class="sourcelist">
			    	<table>
			    		<tr class="firstline">
			    			<td>编号</td>
			    			<td>计划号</td>
			    			<td>时段</td>
			    			<td>数量</td>
			    			<td>计划员</td>
			    			<td class="timetd">创建时间</td>
			    		</tr>
			    	<%
			    	for(Source s:sourcelist){
			    	%>
			  			<tr>
			    			<td><%=s.id %></td>
			    			<td><%=s.mpsNo %></td>
			    			<td><%=s.ts %></td>
			    			<td><%=s.quantity %></td>
			    			<td><%=s.people %></td>
			    			<td class="timetd"><%=s.buildTime %></td>
			    		</tr>
			    	<%
			    	}
			    	%>
			    	</table>
			    </div>
    		</div>
    		
    			 <%
    			 }
    			 %>
    	
    	
    	</div>
    </div>
    <div class="footer">
    	<span>@ L W L</span>
    </div>
  </body>
</html>